﻿using System;
using System.Collections.Generic;
using System.Text;

namespace wikidiom.Pattern
{
    public class PatternResolver
    {
        String pattern = "";
        String content = "";
        public PatternResolver() { }

        public PatternResolver(String content)
        {
            setContent(content);
        }
        public void setContent(String content1)
        {
            this.content = content1;
            content = content.Trim();
            content = content.ToUpper();
            //成语最长不超过16个字
            if (content.Length > 16 || content.Length == 0)
                pattern = "";
            char[] result = "AAAAAAAAAAAAAAAA".ToCharArray();
            char[] letters = "BCDEFGHIJKLMNOPQ".ToCharArray();
            int pos = 0;
            for (int i = 1; i < content.Length; i++)
            {
                bool isSame = false;
                for (int j = i - 1; j >= 0; j--)
                {
                    if (content[i] == content[j])
                    {
                        result[i] = result[j];
                        isSame = true;
                        break;
                    }
                }
                if (!isSame)
                {
                    result[i] = letters[pos];
                    pos++;
                }
            }
            string temp = "";
            for (int i = 0; i < content.Length; i++)
            {
                temp = temp + result[i];
            }
            pattern = temp;
            
        }
        public String getContent()
        {
            return this.content;
        }

    
        public String getPattern()
        {
            return pattern;
        }
    }
}
